package cn.dg.manager.goods.goodsClassify.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import cn.dg.manager.common.dao.impl.BaseDaoImpl;
import cn.dg.manager.common.entity.PageEntity;
import cn.dg.manager.goods.goodsClassify.dao.GoodsTypeDao;
import cn.dg.manager.goods.goodsClassify.entity.GoodsType;

@Repository("GoodsTypeDao")
public class GoodsTypeDaoImpl  extends BaseDaoImpl implements GoodsTypeDao {

	public static final String GOODS_TYPE_SQL_PACKAGE = GoodsTypeDao.class.getName().concat(".");
	
	public PageEntity<GoodsType> findGoodsTypeListPage(Map<String, Object> params) {
		PageEntity<GoodsType> page = new PageEntity<GoodsType>();
		int pg = params.get("page") != null ? Integer.parseInt(String.valueOf(params.get("page"))) : START_PAGE_INDEX;
		page.setPageNo(pg);
		page.setParams(params);
		int i = params.get("rows") != null ? Integer.parseInt(String.valueOf(params.get("rows"))) : END_PAGE_INDEX;
		page.setPageSize(i);
		page.setParams(params);
		List<GoodsType> goodsTypeList = this.sqlSessionTemplate.selectList(GOODS_TYPE_SQL_PACKAGE.concat("findGoodsTypeListPage"), page);
		page.setResults(goodsTypeList);
		return page;
	}

	/**
	 * 插入商品分类表
	 */
	public long insertGoodsType(GoodsType goodsType) {
		return (long) this.sqlSessionTemplate.insert(GOODS_TYPE_SQL_PACKAGE.concat("insertGoodsType"), goodsType);
	}

	/**
	 * 更新商品分类表
	 */
	public long updateGoodsType(GoodsType goodsType) {
		return (long) this.sqlSessionTemplate.insert(GOODS_TYPE_SQL_PACKAGE.concat("updateGoodsType"), goodsType);
	}

	/**
	 * 删除商品分类表
	 */
	public long deleteGoodsType(List<String> typeIdList) {
		return (long) this.sqlSessionTemplate.insert(GOODS_TYPE_SQL_PACKAGE.concat("deleteGoodsType"), typeIdList);
	}

	/**
	 * 获取商品分类信息
	 */
	public List<GoodsType> getGoodsTypeAll() {
		List<GoodsType> goodsTypeList = this.sqlSessionTemplate.selectList(GOODS_TYPE_SQL_PACKAGE.concat("getGoodsTypeAll"));
		return goodsTypeList;
	}
}
